<template>
  <div>
      <div>
    <el-form
      ref="form"
      :model="form"
      label-position="right "
      label-width="100px"
    >
      <el-form-item label="产品名称">
        <el-input v-model="form.paname"></el-input>
      </el-form-item>

      <el-form-item label="还款方式">
    <el-select v-model="form.payment" clearable placeholder="还款方式">
    <el-option
      v-for="item in tableData"
      :key="item.value"
      :label="item.name"
      :value="item.payment">
    </el-option>
  </el-select>
  </el-form-item>

      <el-form-item label="产品介绍">
        <el-input type="textarea" id="aaa" v-model="form.introduce"></el-input>
      </el-form-item>

        <el-form-item label="启用状态">
    <el-select v-model="form.eid" clearable placeholder="启用状态">
    <el-option
      v-for="item in tableData1"
      :key="item.value"
      :label="item.ename"
      :value="item.eid">
    </el-option>
  </el-select>
  </el-form-item>

    </el-form>
  </div><br/>
  
  <div>
      <el-form
      ref="rate"
      :model="rate"
      label-position="right "
      label-width="100px"
     
    >
      <div style="color:red ; font-size:40px" ><h1>产品费率</h1> </div>

      <el-form-item label="期数">
        <el-input v-model="rate.issue"></el-input>
      </el-form-item>

      <el-form-item label="月利率">
        <el-input v-model="rate.monthrate"></el-input>
      </el-form-item>

 <el-form-item>
        <el-button type="primary" @click="onSubmit">确定</el-button>
        <el-button>取消</el-button>
      </el-form-item>
      </el-form>
  </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
        tableData: [],
        tableData1: [],
      form: {
        paname: "",
        payment: "",
        introduce: "",
        pstatu: "",
        eid: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      rate: {
          issue: "",
          monthrate: ""
      }
    };
  },
  created(){
this.getRepaymentAll();
this.getEnablestatusAll();
},
  methods: {
//查询还款方式表单中的所有信息 名称展示到下拉框
getRepaymentAll(){
        this.$axios.get("http://localhost:8601/products/allRepayment").then(resp=>{
          this.tableData=resp.data;
          console.log(resp);
        });
},

//查询启用状态表单中的所有信息 名称展示到下拉框
getEnablestatusAll(){
        this.$axios.get("http://localhost:8601/products/all").then(resp=>{
          this.tableData1=resp.data;
          console.log(resp);
        });
},

    onSubmit() {
      console.log("submit!");
      //点击提交将数据传递到后端 添加数据
            this.$axios
        .get("http://localhost:8601/products/add", {
        params: {
            paname:this.form.paname,
            payment:this.form.payment,
            introduce:this.form.introduce,
            pstatu: this.form.pstatu,
            eid: this.form.eid,
             issue:this.rate.issue,
            monthrate:this.rate.monthrate,
          },
        })
        .then((resp) => {
          console.log(resp);
        });
      console.log("submit!");
      this.$message({
        message: "添加成功",
        type: "success",
      });
      
    }


  },
};
</script>

<style>
#aaa{
  height: 200px;
}

div{margin: 0ex; padding: 0ex;}.con{float: left;}
</style>